<template>
  <div class="search-result" :class="{ 'search-hide': searchHide }">
    <div class="result" v-if="isFocus">
      <h3 class="title">热搜榜</h3>
      <ul class="result-lists">
        <li
          class="list"
          v-for="(item, index) in hotSearchLists"
          :key="item.score"
          @click="transition(item.searchWord)"
        >
          <span class="count">{{ index + 1 }}</span>
          <div class="song">
            <p class="song-name">
              <span class="name">{{ item.searchWord }}</span>
              <span class="hot">HOT</span>
              <span class="hot-count">{{ item.score }}</span>
            </p>
            <p class="song-des">{{ item.content }}</p>
          </div>
        </li>
      </ul>
    </div>
    <div class="search-word" v-else>
      <div class="title">
        搜 <span class="active">"{{ word }}"</span>相关的结果>
      </div>
      <ul class="singer-songs">
        <div class="title"><a-icon type="play-circle" /> 单曲</div>
        <li
          class="song"
          v-for="item in searchWords"
          :key="item.id"
          @click="setId(item.id)"
        >
          <span class="song-name">{{ item.name }}</span>
          <span class="song-des" v-if="item.alias.length">{{
            item.alias.join(" ")
          }}</span>
          -
          <span class="song-author">{{ resolveName(item.artists) }}</span>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
export default {
  name: "SearchBox",
  props: ["searchHide", "word", "isFocus", "hotSearchLists", "searchWords"],
  data() {
    return {};
  },
  methods: {
    // 多个歌手拼接
    resolveName(arr) {
      if (Array.isArray(arr)) {
        return arr.map((item) => item.name).join(",");
      } else {
        return "";
      }
    },
    // 传递id到播放器
    setId(id) {
      this.$bus.$emit("changeId", id);
    },
    transition(word) {
      this.$router.push(`/main/search/${word}`);
    },
  },
};
</script>

<style lang="scss" scoped>
.search-result {
  z-index: 20;
  position: absolute;
  top: 6rem;
  left: 24rem;
  width: 34rem;
  height: 40rem;
  background: #fff;
  overflow: auto;
  .result {
    .title {
      padding: 1rem;
      font-size: 1.8rem;
      color: #333;
    }
    .result-lists {
      .list {
        display: flex;
        height: 5rem;
        margin: 1rem 0;
        cursor: pointer;
        .count {
          height: 100%;
          width: 6rem;
          line-height: 5rem;
          text-align: center;
          font-weight: bold;
          color: #f40;
        }
        .song {
          .song-name {
            font-weight: bold;
            margin-bottom: 0;
          }
          .hot {
            color: #f40;
            font-weight: bold;
            margin: 0 1rem;
          }
          .hot-count {
            color: #ccc;
            font-weight: normal;
          }
        }
      }
    }
  }
  .search-word {
    .title {
      height: 3rem;
      padding: 0.5rem;
      .active {
        color: lightblue;
      }
    }
    .singer-songs {
      margin-top: 0.3rem;
      .title {
        padding: 0.5rem 1rem;
        background: rgba(245, 245, 247);
      }
      .song {
        font-size: 1.3rem;
        cursor: pointer;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        padding: 1rem 2.5rem;
        .song-name {
          color: lightblue;
        }
        .song-des {
          color: #ccc;
          margin: 0 1rem;
        }
      }
    }
  }
}
.search-result.search-hide {
  display: none;
}
// 滚动条样式
.search-result::-webkit-scrollbar {
  width: 5px;
  height: 1px;
}

.search-result::-webkit-scrollbar-thumb {
  border-radius: 5px;
  background: #eee;
}

.search-result::-webkit-scrollbar-track {
  /*滚动条里面轨道*/
  border-radius: 5px;
  background: #fff;
}
</style>